package org.springcloud.wisdom.spring_02_classroom.admin.managestudent.dao;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springcloud.wisdom.spring_02_classroom.student.sschedule.entity.Student;

import java.util.List;

@Mapper
public interface ManageStudentDao {
    //管理员可以通过学号重置学生登录密码
    @Update("UPDATE student " +
            "SET  adpass=#{adpass} " +
            "WHERE sid=#{sid}")
    int updateStudentPassword(Student student);

    //基于课模糊查询学号和姓名的分页查看所有学生信息
    @Select("<script>" +
            "SELECT * " +
            "FROM student " +
            "<where>" +
            "    <if test=\"sname != null\">" +
            " <bind name=\"Key\" value=\"'%'+sname+'%'\"/>" +
            "                        sname like #{Key} " +
            "    </if>" +
            "    <if test=\"sid != null\">" +
            " <bind name=\"Key\" value=\"'%'+sid+'%'\"/>" +
            "                and        sid like #{Key} " +
            "    </if> " +
            "</where>" +
            "LIMIT #{start}, #{size} "+
            "</script>")
    public List<Student> get(int start, int size, String sid ,String sname );

    @Select("<script>" +
            "SELECT count(*) FROM student" +
            "<where>" +
            "    <if test=\"sname != null\">" +
            " <bind name=\"Key\" value=\"'%'+sname+'%'\"/>" +
            "                        sname like #{Key} " +
            "    </if>" +
            "    <if test=\"sid != null\">" +
            " <bind name=\"Key\" value=\"'%'+sid+'%'\"/>" +
            "                and        sid like #{Key} " +
            "    </if> " +
            "</where>" +
            "</script>")
    public int CountStudents(  String sid ,String sname );
}
